(include 'class/seq/class.inc)

(def-class 'str 'seq)
(dec-method 'vtable 'class/str/vtable)
(dec-method 'create_from_buffer 'class/str/create_from_buffer 'static '(r0 r1) '(r0))
(dec-method 'create_from_cstr 'class/str/create_from_cstr 'static '(r0) '(r0))
(dec-method 'create_from_file 'class/str/create_from_file 'static '(r0) '(r0))
(dec-method 'create_from_long 'class/str/create_from_long 'static '(r0 r1) '(r0))
(dec-method 'append 'class/str/append 'static '(r0 r1) '(r0))
(dec-method 'init 'class/str/init 'static '(r0 r1 r2 r3))
(dec-method 'init1 'class/str/init1 'static '(r0 r1 r2 r3) '(r0 r1))
(dec-method 'init2 'class/str/init2 'static '(r0 r1 r2 r3) '(r0 r1))
(dec-method 'init3 'class/str/init3 'static '(r0 r1 r2) '(r0 r1))
(dec-method 'split 'class/str/split 'static '(r0 r1) '(r0 r1))
(dec-method 'compare 'class/str/compare 'static '(r0 r1) '(r0 r1))
(dec-method 'same 'class/str/same 'static '(r0 r1) '(r0 r1))
(dec-method 'find 'class/str/find 'static '(r0 r1) '(r0 r1 r2))

(dec-method 'print 'class/str/print 'override)

(dec-method 'hash 'class/str/hash 'final)
(dec-method 'get_length 'class/str/get_length 'final)
(dec-method 'ref_element 'class/str/ref_element 'final)
(dec-method 'slice 'class/str/slice 'final)
(dec-method 'cat 'class/str/cat 'final)

(dec-method 'lisp_str 'class/str/lisp_str 'static '(r0 r1) '(r0 r1))
(dec-method 'lisp_split 'class/str/lisp_split 'static '(r0 r1) '(r0 r1))
(dec-method 'lisp_code 'class/str/lisp_code 'static '(r0 r1) '(r0 r1))
(dec-method 'lisp_char 'class/str/lisp_char 'static '(r0 r1) '(r0 r1))
(dec-method 'lisp_cmp 'class/str/lisp_cmp 'static '(r0 r1) '(r0 r1))
(dec-method 'lisp_save 'class/str/lisp_save 'static '(r0 r1) '(r0 r1))
(dec-method 'lisp_load 'class/str/lisp_load 'static '(r0 r1) '(r0 r1))

(def-struct 'str 'seq)
	(uint 'length 'hashcode)
	(local-align)
	(offset 'data)
(def-struct-end)

(defun roundup (_)
	(setq _ (dec _))
	(setq _ (logior _ (>> _ 32)))
	(setq _ (logior _ (>> _ 16)))
	(setq _ (logior _ (>> _ 8)))
	(setq _ (logior _ (>> _ 4)))
	(setq _ (logior _ (>> _ 2)))
	(setq _ (logior _ (>> _ 1)))
	(inc _))

(defcvar 'str_gap (- (* 2 (roundup (+ str_data byte_size))) (+ str_data byte_size)))

(defcvar 'char_backspace 8)
(defcvar 'char_tab 9)
(defcvar 'char_lf 10)
(defcvar 'char_cr 13)
(defcvar 'char_esc 27)
(defcvar 'char_space (ascii-code " "))
(defcvar 'char_underscore (ascii-code "_"))
(defcvar 'char_pipe (ascii-code "|"))
(defcvar 'char_hash (ascii-code "#"))
(defcvar 'char_lrb (ascii-code "("))
(defcvar 'char_rrb (ascii-code ")"))
(defcvar 'char_lsb (ascii-code "["))
(defcvar 'char_rsb (ascii-code "]"))
(defcvar 'char_lcb (ascii-code "{"))
(defcvar 'char_rcb (ascii-code "}"))
(defcvar 'char_quote (ascii-code "'"))
(defcvar 'char_double_quote 34)
(defcvar 'char_tick (ascii-code "`"))
(defcvar 'char_comma (ascii-code ","))
(defcvar 'char_tilda (ascii-code "~"))
(defcvar 'char_semi (ascii-code ";"))
(defcvar 'char_dot (ascii-code "."))
(defcvar 'char_at (ascii-code "@"))
(defcvar 'char_lt (ascii-code "<"))
(defcvar 'char_gt (ascii-code ">"))
(defcvar 'char_equal (ascii-code "="))
(defcvar 'char_plus (ascii-code "+"))
(defcvar 'char_minus (ascii-code "-"))
(defcvar 'char_multiply (ascii-code "*"))
(defcvar 'char_divide (ascii-code "/"))
(defcvar 'char_0 (ascii-code "0"))
(defcvar 'char_9 (ascii-code "9"))
(defcvar 'char_a (ascii-code "a"))
(defcvar 'char_z (ascii-code "z"))
(defcvar 'char_A (ascii-code "A"))
(defcvar 'char_Z (ascii-code "Z"))
(defcvar 'char_x (ascii-code "x"))
(defcvar 'char_b (ascii-code "b"))
(defcvar 'char_o (ascii-code "o"))

;;;;;;;;;;;;;;;;
; inline methods
;;;;;;;;;;;;;;;;

(defcfun-bind class/str/get_length ()
	;inputs
	;r0 = str object (ptr)
	;outputs
	;r0 = str object (ptr)
	;r1 = string length (bytes)
	;trashes
	;r1
	(assign '((r0 str_length)) '(r1)))
